import sys

from PySide6.QtCore import QSize
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QPushButton, QWidget, QFrame, QVBoxLayout, QComboBox, QStackedWidget, QApplication
from WidgetElementsParams.StraightPipeWidget import StraightPipeWidget as spw
from WidgetElementsParams.CurvePipeWidget import CurvePipeWidget as cpw
from WidgetElementsParams.ElbowWidget import ElbowWidget as ew
import styles.styles_elements as styles


class WindowElemParams(QWidget):
    def __init__(self, parent=None):
        super(WindowElemParams, self).__init__(parent)

        # Создание слоя с рамкой окна
        self.vlayout_frame = QVBoxLayout(self)
        self.frame = QFrame(self)
        self.frame.setObjectName('frame')
        self.frame.setStyleSheet(styles.QFrame_StyleSheet)

        # установка рамки на основной слой
        self.vlayout = QVBoxLayout(self.frame)

        # Размер окна и оформление
        self.resize(400, 540)
        self.setObjectName('widget')
        self.setStyleSheet(styles.QWidget_StyleSheet)

        self.setWindowTitle('Параметры элемента')

        self.straight_pipe = spw()
        self.curve_pipe = cpw()
        self.elbow = ew()

        # Создание выпадающего списка типа элемента
        self.choose_type_elem_cb = QComboBox(self.frame)
        self.choose_type_elem_cb.setObjectName('type_element')
        self.choose_type_elem_cb.setStyleSheet(styles.QComboBox_StyleSheet)

        self.choose_type_elem_cb.setPlaceholderText('Выбор типа элемента')
        self.choose_type_elem_cb.addItems(('Прямой участок', 'Изогнутый участок', 'Угольник'))

        # Создание стэка виджетов

        self.stacked_widget = QStackedWidget(self.frame)
        self.stacked_widget.setObjectName('stack_widget')
        self.stacked_widget.setStyleSheet(styles.QStackedWidget_StyleSheet)
        self.stacked_widget.addWidget(self.straight_pipe)
        self.stacked_widget.addWidget(self.curve_pipe)
        self.stacked_widget.addWidget(self.elbow)

        # Создание виджета кнопки "Add element"
        self.btn_save_element = QPushButton(self.frame)
        self.btn_save_element.setObjectName('pushbutton')
        self.btn_save_element.setStyleSheet(styles.QPushButton_StyleSheet)
        self.btn_save_element.setText('Добавить элемент')
        icon = QIcon()
        icon.addFile(r'user_interface\icons\done_white_24dp.svg',
                     QSize(), QIcon.Normal, QIcon.Off)
        self.btn_save_element.setIcon(icon)
        self.btn_save_element.setIconSize(QSize(24, 24))

        # Отображение виджетов в окне

        self.vlayout_frame.addWidget(self.frame)
        self.vlayout.addWidget(self.choose_type_elem_cb)
        self.vlayout.addWidget(self.stacked_widget)
        self.vlayout.addWidget(self.btn_save_element)

        self.setLayout(self.vlayout)

        self.choose_type_elem_cb.currentIndexChanged.connect(self.stacked_widget.setCurrentIndex)

    def get_element_type(self):
        return {self.choose_type_elem_cb: self.choose_type_elem_cb.currentText()}

    def get_params_current_widget(self):
        params_current_widget = self.stacked_widget.currentWidget().get_params_element()
        params_current_widget.update(self.get_element_type())
        return params_current_widget

    def get_name_params_element(self):
        return self.stacked_widget.currentWidget().get_name_params_element()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = WindowElemParams()
    window.show()
    sys.exit(app.exec())
